package org.callisto.handlers;

import java.util.Observable;
import java.util.Observer;

import org.callisto.model.Event;
import org.callisto.model.Keyboard;

public abstract class KeyboardObserver implements Observer {

	Keyboard keyboard;
	
	public KeyboardObserver(Keyboard keyboard) {
		this.keyboard = keyboard;
	}
	
	public void update(Observable o, Object arg) {
		if (o instanceof Keyboard && arg instanceof Event) {
			try {
				handleEvent((Event) arg);
			} catch (Exception e) {
				System.out.println("Error executing MIDI event handler");
				e.printStackTrace();
			}
		} else {
			try {
				throw new Exception("Arguments must be of class Keyboard/Event");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	abstract public void handleEvent (Event event) throws Exception;
}
